This repository was archived by the owner on Jan 19, 2026. It is now read-only.
feat: types-generate-cmd#169
Merged
Merged
Conversation
…tion - Introduced new utility functions in `format.ts` for converting strings to PascalCase, CamelCase, and SnakeCase. - Added functions for masking tokens, slugifying text, and recursively removing properties from objects. - Implemented a method to convert objects to string parameters for URLSearchParams. - Created a function to generate regex patterns from glob patterns. - Updated `index.ts` to export the new formatting utilities.
- Refactored the type generation logic to improve handling of component types, including sanitization of component names. - Introduced a new `ComponentPropertySchema` interface and related types in `schemas.ts` for better type safety and organization. - Updated the `generateStoryblokTypes` function to read type definitions from an external file, ensuring a more robust extraction process. - Removed redundant type definitions from `storyblok.ts` to streamline the codebase and avoid duplication.
- Added support for component restrictions based on groups and individual whitelists in `getComponentPropertiesTypeAnnotations`. - Introduced a new parameter `componentsMaps` to facilitate the mapping of component groups and names. - Updated the `generateTypes` function to pass the new `componentsMaps` parameter, improving type safety and flexibility in handling component properties.
- Updated `generateTypes` and `getComponentPropertiesTypeAnnotations` functions to utilize `spaceData` instead of `componentsMaps`, improving type safety and flexibility. - Added null checks for `spaceData.components` to prevent runtime errors. - Removed the redundant `generateComponentGroupsAndComponentNames` function to streamline the codebase. - Improved error handling in the `generateTypes` function by implementing a try/catch block to manage asynchronous errors effectively.
- Refactored `GenerateTypesOptions` to replace `typeNamesPrefix` and `typeNamesSuffix` with a single `typePrefix` option for improved clarity and usability. - Enhanced `getComponentType` function to utilize the new `typePrefix` option, simplifying the type name generation process. - Updated command options in `index.ts` to include `--type-prefix` for better user experience when generating component types. - Adjusted handling of Storyblok property types to ensure consistent type generation without unnecessary prefixes.
- Introduced a new launch configuration in `.vscode/launch.json` for debugging the type generation process with separate files. - This configuration allows for easier debugging of the type generation command, enhancing the development experience.
- Removed the optional `[componentName]` parameter from the `generate` command to streamline the command usage. - Eliminated the `--fi, --filter <filter>` option to reduce complexity in type generation, focusing on essential flags for better clarity and usability.
- Added a new `suffix` option to the `GenerateTypesOptions` interface to allow for suffix customization during type generation. - Updated the `generate` command in `index.ts` to utilize the new `suffix` option, improving flexibility in type generation. - Modified the VSCode launch configuration to include a new debug option for generating types with a specified suffix, enhancing the development experience.
- Added a new `customFieldsParser` option to the `GenerateTypesOptions` interface, allowing for custom field type handling during type generation. - Introduced a `custom-fields-parser.ts` file to define the structure for the 'native-color-picker' field type. - Updated the `getComponentPropertiesTypeAnnotations` function to utilize the custom fields parser when available, enhancing flexibility in type generation. - Enhanced the `generate` command in `index.ts` to support the new `--custom-fields-parser` option for specifying the parser file path. - Modified the VSCode launch configuration to include a debug option for generating types with a custom fields parser, improving the development experience.
- Introduced a new `compilerOptions` option in the `GenerateTypesOptions` interface to allow for custom compiler configurations during type generation. - Implemented a `compiler-options.ts` file to define default compiler settings. - Updated the `generateTypes` function to load and apply compiler options when generating types, enhancing flexibility and customization. - Enhanced the `getComponentPropertiesTypeAnnotations` function to support the new `customFieldsParser` type definition. - Modified the VSCode launch configuration to include a debug option for generating types with specified compiler options, improving the development experience.
- Introduced a new test file `actions.test.ts` to validate the functionality of type generation actions. - Implemented tests for `generateTypes` and `getComponentType` functions, covering various scenarios including strict mode, custom fields parser, and component property type annotations. - Mocked necessary modules and created a virtual file system to simulate file operations, ensuring isolated and reliable tests. - Enhanced test coverage for handling different property types such as text, textarea, number, boolean, multilink, and custom types. - Verified that generated types align with expected outputs, improving the robustness of the type generation feature.
- Introduced a new test file `index.test.ts` to validate the functionality of the type generation command. - Implemented tests for various scenarios including successful type generation, strict mode, type prefix, suffix, separate files, custom fields parser, and compiler options. - Mocked necessary modules and created a controlled environment to ensure isolated and reliable tests. - Enhanced test coverage for different command options, improving the robustness of the type generation feature.
- Removed the unused `CommandError` import from `index.test.ts` to clean up the code and improve readability. - This change helps maintain a tidy codebase by eliminating unnecessary dependencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type Generation Command
The Storyblok type generation command allows you to generate TypeScript type definitions for your Storyblok components. This is particularly useful for ensuring type safety when working with Storyblok content in your frontend applications.
Prerequisites
Before generating types, ensure you have:
storyblok components pullcommandBasic Usage
Architecture & Flow
The type generation command is organized in three main layers with a specific processing flow to ensure accurate type generation.
Command Structure
Processing Flow Examples
1. Basic Type Generation
Flow:
Read Phase
Generation Phase
Save Phase
2. Strict Mode Type Generation
Flow:
Generation Phase
Type Annotation Example
3. Custom Type Prefix
storyblok types generate --space 12345 --type-prefix "Custom"Flow:
Component Type Generation
4. Separate Files Generation
Flow:
File Generation
5. Custom Fields Parser
Flow:
Parser Loading
Key Features
Type Safety
Customization Options
Custom Field Support
Storyblok Type Definitions
Type Generation File Structure
Generated type files follow this structure:
Testing Strategy
The command includes comprehensive test coverage:
Unit Tests
Testing Checklist
Running Type Generation
General
Required Arguments
--space=TARGET_SPACE_IDOptions
--strict--type-prefix=<prefix>--suffix=<suffix>--separate-files--custom-fields-parser=<path>--compiler-options=<options>Error Handling